<template>

<div>
    <div style="margin: 0 auto; max-width: 400px; text-align: center;">
    <el-input placeholder="请输入云控帐号" v-model="cloud_uid">
      <template slot="prepend">帐号</template>
    </el-input>
    </div>

    <div style="margin:20px auto;max-width: 400px;text-align: center;">
      <el-input placeholder="请输入云控密码" v-model="cloud_pwd">
        <template slot="prepend">密码</template>
      </el-input>
    </div>

    <div style="margin:20px auto;max-width: 400px;text-align: center;">
      <el-button v-on:click="login_go()" size="medium" type="primary">登录</el-button>
      <el-button v-on:click="reg_go()" size="medium" type="primary">注册</el-button>
    </div>
 </div>
</template>

<script type="text/javascript">
    import axios from 'axios'
    export default {
        data () {
          
          let cloud_uid = localStorage.getItem("cloud_uid")
          let cloud_pwd = localStorage.getItem("cloud_pwd")
          return {
               cloud_uid: cloud_uid,
               cloud_pwd: cloud_pwd
          }
        },
        created: function () {
          let cloud_uid = localStorage.getItem("cloud_uid")
          let cloud_pwd = localStorage.getItem("cloud_pwd")
          if (typeof cloud_pwd != 'undefined' && cloud_pwd != '') {
            axios.post('/task/html/login', {
                uid: cloud_uid,
                pwd: cloud_pwd
              })
              .then(function (response) {
                if (response.status == 200) {
                  if (response.data.code == 1) {
                    window.location.href="/html/main.html"
                  }
                }
                console.log(response);
              });
          }
        },
        methods: {
            msgbox:function(msg){
              vm.$message({
                    showClose: true,
                    message: msg,
                    type: 'error'
                  });
            },
            reg_go: function(){
              window.location.href="/html/reg.html"
            },
            login_go: function () {
              axios.post('/task/html/login', {
                uid: this.cloud_uid,
                pwd: this.cloud_pwd
              })
              .then(function (response) {
                if (response.status == 200) {
                  if (response.data.code == 1) {
                    localStorage.setItem('cloud_uid', vm.cloud_uid)
                    localStorage.setItem('cloud_pwd', vm.cloud_pwd);
                    // 跳界面
                    window.location.href="/html/main.html"
                  }else{
                    vm.msgbox('登录失败');
                  }
                }
                console.log(response);
              })
              .catch(function (error) {
                vm.$message.error(error);
                console.log(error);
              });
            }
          }
    })




</script>
